package com.jic.manager.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Oauth2 client_secret加密
 */
public class Oauth2EncodedUtils {

    public static String encode(String pa){
        return new BCryptPasswordEncoder().encode(pa);
    }

    public static void main(String[] args) {
        System.out.println(encode("123456"));

        System.out.println(extractTokenKey("d4fb056c-1b77-4572-9363-95cb8271b57f"));
    }
    public static String extractTokenKey(String value) {
        if (value == null) {
            return null;
        } else {
            MessageDigest digest;
            try {
                digest = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException var5) {
                throw new IllegalStateException("MD5 algorithm not available.  Fatal (should be in the JDK).");
            }

            try {
                byte[] bytes = digest.digest(value.getBytes("UTF-8"));
                return String.format("%032x", new BigInteger(1, bytes));
            } catch (UnsupportedEncodingException var4) {
                throw new IllegalStateException("UTF-8 encoding not available.  Fatal (should be in the JDK).");
            }
        }
    }
}
